/**
 * 调用WG相关http接口
 */

import httpUtil from './index.js'

// 获取wg列表
export function getAllWG () {
  return httpUtil({
    url: "/wginfo/findAll",
    method: "get",
  })
}

// 根据人员条件获取wg列表
export function getWG (e, userId, pagesize, pagenum) {
  let url = "/wginfo/findAll?pagesize=" + pagesize + "&pagenum=" + pagenum
  if(e === "my") {
    url = "/wginfo/findOwnedWGById/?userId=" + userId + "&pagesize=" + pagesize + "&pagenum=" + pagenum
  }else if(e === "join") {
    url = "/wginfo/findJoinedWGById?userId=" + userId + "&pagesize=" + pagesize + "&pagenum=" + pagenum
  }else if(e === "focus") {
    url = "/wginfo/findFocusedWGById?userId=" + userId + "&pagesize=" + pagesize + "&pagenum=" + pagenum
  }
  return httpUtil({
    "url": url,
    method: "get",
  })
}

// 根据id获取wg
export function getWGById (e) {
  return httpUtil({
    url: "/wginfo/" + e,
    method: "get",
  })
}

// 获取wg的人员
export function getWGUserById (wgId) {
  return httpUtil({
    url: "/wginfo/getMembers?wgId=" + wgId,
    method: "get"
  })
}

// 根据条件搜索任务
export function queryWG (startTime, endTime, creator, focusId, pagesize, pagenum, focusFlag, wgName) {
  let url = "/wginfo/queryWG?pagesize=" + pagesize + "&pagenum=" + pagenum
  if(startTime && startTime != "") {
    url += "&startTime="+startTime
  }
  if(endTime && endTime != "") {
    url += "&endTime="+endTime
  }
  if(creator && creator != "") {
    url += "&creator="+creator
  }
  if(focusId && focusId != 0) {
    url += "&focusUserId="+focusId
  }
  if(wgName && wgName != "") {
    url += "&wgName="+wgName
  }
  
  url += "&focusFlag="+focusFlag
  
  return httpUtil({
    url,
    method: "get",
  })
}

// 关注任务
export function addFocusWG (data) {
  return httpUtil({
    url: "/focus",
    method: "post",
    data
  })
}

// 取消关注
export function cancelFocusWg (data) {
  return httpUtil({
    url: "/focus",
    method: "delete",
    data
  })
}


// 添加成员
export function addMember (data) {
  return httpUtil({
    url: "/wginfo/members/",
    method: "post",
    data
  })
}

// 删除成员
export function delMember (data) {
  return httpUtil({
    url: "/wginfo/deleteMember/",
    method: "delete",
    data
  })
}


// 修改wg
export function completeWG (data) {
  return httpUtil({
    url: "/wginfo/completeWG/",
    method: "patch",
    data
  })
}

// 添加一条wg
export function addWG (data) {
  return httpUtil({
    url: "/wginfo",
    method: "post",
    data
  })
}
